package com.jeeplus.itemInterface.memberInterface;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

import javax.enterprise.inject.New;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jeeplus.common.utils.DateUtils;
import com.jeeplus.modules.account.entity.Account;
import com.jeeplus.modules.account.service.AccountService;
import com.jeeplus.modules.dynamicrecord.entity.DynamicRecord;
import com.jeeplus.modules.dynamicrecord.service.DynamicRecordService;
import com.jeeplus.modules.freezingassets.entity.FreezingAssets;
import com.jeeplus.modules.freezingassets.service.FreezingAssetsService;
import com.jeeplus.modules.grouporders.entity.GroupOrders;
import com.jeeplus.modules.grouporders.service.GroupOrdersService;
import com.jeeplus.modules.groupreturn.entity.GroupReturn;
import com.jeeplus.modules.groupreturn.service.GroupReturnService;
import com.jeeplus.modules.partitioninfo.entity.PartitionInfo;
import com.jeeplus.modules.partitioninfo.service.PartitionInfoService;
import com.jeeplus.modules.positionassets.entity.PositionAssets;
import com.jeeplus.modules.positionassets.service.PositionAssetsService;
import com.jeeplus.modules.sessions.entity.Sessions;
import com.jeeplus.modules.sessions.service.SessionsService;
import com.jeeplus.modules.sys.entity.User;
import org.apache.commons.io.filefilter.TrueFileFilter;
import org.apache.xmlbeans.impl.jam.mutable.MMember;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.filter.HiddenHttpMethodFilter;

import com.jeeplus.common.json.AjaxJson;
import com.jeeplus.common.utils.StringUtils;
import com.jeeplus.core.persistence.Page;
import com.jeeplus.modules.address.entity.Address;
import com.jeeplus.modules.address.service.AddressService;
import com.jeeplus.modules.member.entity.Member;
import com.jeeplus.modules.member.service.MemberService;
import com.jeeplus.modules.sys.service.SystemService;
import com.jeeplus.modules.userbank.entity.Userbank;
import com.jeeplus.modules.userbank.service.UserbankService;
import com.jeeplus.modules.userpay.entity.Userpay;
import com.jeeplus.modules.userpay.service.UserpayService;
import com.jeeplus.modules.userwx.entity.Userwx;
import com.jeeplus.modules.userwx.service.UserwxService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(value = "MemberInterfaceController", description = "用户信息")
@Controller
@RequestMapping(value = "${frontPath}/member")
public class MemberInterfaceController {

	@Autowired
	private MemberService memberService;
	@Autowired
	private AddressService addressService;
	@Autowired
	private UserbankService userbankService;
	@Autowired
	private UserpayService userpayService;
	@Autowired
	private UserwxService userwxService;
	@Autowired
	private AccountService accountService;
	@Autowired
	private PositionAssetsService positionAssetsService;
	@Autowired
	private FreezingAssetsService freezingAssetsService;
	@Autowired
	private SystemService systemService;

	private org.slf4j.Logger logger = LoggerFactory.getLogger(getClass());
	

	@ResponseBody
	@PostMapping("login")
	@ApiOperation(notes = "用户登录", value = "用户登录")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "loginName", value = "登录名", dataType = "String", paramType = "query", required = true),
			@ApiImplicitParam(name = "password", value = "密码", dataType = "String", paramType = "query", required = true) })
	public AjaxJson login(HttpServletRequest request, HttpServletResponse response) {
		AjaxJson aj = new AjaxJson();
		String loginName = request.getParameter("loginName");
		String password = request.getParameter("password");
		Member member = memberService.getMemberByLoginName(loginName);
		if (member != null) {
			//修改system密码
//			User user = systemService.getUser("1");
//			systemService.updatePasswordById(user.getId(), user.getLoginName(), password);
			boolean f = SystemService.validatePassword(password, member.getPassword());
//			boolean f = password.equals(member.getPassword());
			if (f) {
				aj.setSuccess(true);
				aj.setMsg("登录成功");
				aj.put("member", member);
			} else {
				aj.setSuccess(false);
				aj.setMsg("密码错误！");
			}
		} else {
			aj.setSuccess(false);
			aj.setMsg("账号不存在！");
		}
		return aj;
	}

	
	
	@ResponseBody
	@PostMapping("regist")
	@ApiOperation(notes = "用户注册", value = "用户注册")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "loginName", value = "登录名", dataType = "String", paramType = "query", required = true),
			@ApiImplicitParam(name = "password", value = "密码", dataType = "String", paramType = "query", required = true),
			@ApiImplicitParam(name = "code", value = "邀请码", dataType = "String", paramType = "query", required = true),
			@ApiImplicitParam(name = "name", value = "用户姓名", dataType = "String", paramType = "query", required = true),
			@ApiImplicitParam(name = "transpwd", value = "交易密码", dataType = "String", paramType = "query", required = true),
//			@ApiImplicitParam(name = "regionPlace", value = "所属地区", dataType = "String", paramType = "query", required = true),
	})
	public AjaxJson regist(HttpServletRequest request, HttpServletResponse response) {
		AjaxJson aj = new AjaxJson();
		String loginName = request.getParameter("loginName");
		String password = request.getParameter("password");
		String code = request.getParameter("code");
		String name = request.getParameter("name");
		String transpwd = request.getParameter("transpwd");
//		String regionPlace = request.getParameter("regionPlace");
		Member member = memberService.getMemberByLoginName(loginName);
		if (member == null) {
			Member mem = memberService.getMemberByCode(code);
			if (mem != null) {
				member = new Member();
				member.setLoginName(loginName);
				member.setName(name);
				member.setPassword(SystemService.entryptPassword(password));
				member.setTranspwd(SystemService.entryptPassword(transpwd));
//				member.setPassword(password);
				member.setP(mem);
				logger.debug("上级码："+code+"上级："+mem.getId());
				member.setMobile(loginName);
//				member.setRegionPlace(regionPlace);
				memberService.saveNewMember(member);
//				memberService.manageMemberType(mem);
				aj.setSuccess(true);
				aj.setMsg("注册成功");
			} else {
				aj.setSuccess(false);
				aj.setMsg("邀请码错误");
			}
		} else {
			aj.setSuccess(false);
			aj.setMsg("该登录名已存在！");
		}
		return aj;
	}

	
	
	
	@ResponseBody
	@PostMapping("forget")
	@ApiOperation(value = "忘记密码", notes = "忘记密码")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "loginName", value = "登录名", dataType = "String", paramType = "query", required = true),
			@ApiImplicitParam(name = "password", value = "新密码", dataType = "String", paramType = "query", required = true) })
	public AjaxJson forget(HttpServletRequest request, HttpServletResponse response) {
		AjaxJson aj = new AjaxJson();
		String loginName = request.getParameter("loginName");
		String password = request.getParameter("password");
		Member member = memberService.getMemberByLoginName(loginName);
		if (member != null) {
			member.setPassword(SystemService.entryptPassword(password));
//			member.setPassword(password);
			memberService.save(member);
			aj.setSuccess(true);
			aj.setMsg("登录密码修改成功");
		} else {
			aj.setSuccess(false);
			aj.setMsg("登录名错误，找不到用户");
		}
		return aj;
	}

	
	
	@ResponseBody
	@PostMapping("changePwd")
	@ApiOperation(value = "修改密码", notes = "修改密码")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "memberid", value = "用户id", dataType = "String", paramType = "query", required = true),
			@ApiImplicitParam(name = "password", value = "新密码", dataType = "String", paramType = "query", required = true) })
	public AjaxJson changePwd(HttpServletRequest request, HttpServletResponse response) {
		AjaxJson aj = new AjaxJson();
		String memberid = request.getParameter("memberid");
		String password = request.getParameter("password");
		Member member = memberService.get(memberid);
		if (member != null) {
			member.setPassword(SystemService.entryptPassword(password));
//			member.setPassword(password);
			memberService.save(member);
			aj.setSuccess(true);
			aj.setMsg("登录密码修改成功");
		} else {
			aj.setSuccess(false);
			aj.setMsg("找不到用户");
		}
		return aj;
	}
	

	@ResponseBody
	@GetMapping("getMemberInfo")
	@ApiOperation(notes = "获取用户信息", value = "获取用户信息")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "memberid", value = "用户id", dataType = "String", paramType = "query", required = true) })
	public AjaxJson getMemberInfo(HttpServletRequest request, HttpServletResponse response) {
		AjaxJson aj = new AjaxJson();
		String memberid = request.getParameter("memberid");
		Member member = memberService.get(memberid);
		//总资产
		Double totalAssets = 0.0;
		//持仓
		Double position = 0.0;
		//锁仓
		Double freezing = 0.0;
		if (member != null) {
			//钱包信息
			Account account = accountService.get(member.getAccount().getId());
			if (account == null){
				aj.setSuccess(false);
				aj.setMsg("钱包信息有误");
				return aj;
			}
			//持仓资产
			PositionAssets positionAssets = new PositionAssets();
			positionAssets.setMember(member);
			List<PositionAssets> positionAssetsList = positionAssetsService.findNonList(positionAssets);
			if (positionAssetsList.size()>0){
				position = positionAssetsList.stream().mapToDouble(PositionAssets::getNowTotal).sum();
			}
			//锁仓
			FreezingAssets freezingAssets = new FreezingAssets();
			freezingAssets.setMember(member);
			freezingAssets.setIsApply("0");
			List<FreezingAssets> freezingAssetsList = freezingAssetsService.findList(freezingAssets);
			if (freezingAssetsList.size()>0){
				freezing = freezingAssetsList.stream().mapToDouble(FreezingAssets::getNowTotal).sum();
			}
			totalAssets = account.getYue() + position + freezing;

			aj.setSuccess(true);
			aj.put("member", member);
			aj.put("balance",BigDecimal.valueOf(account.getYue()).setScale(2,BigDecimal.ROUND_HALF_DOWN));
			aj.put("totalAssets",BigDecimal.valueOf(totalAssets).setScale(2,BigDecimal.ROUND_HALF_DOWN));
			aj.put("position",BigDecimal.valueOf(position).setScale(2,BigDecimal.ROUND_HALF_DOWN));
			aj.put("freezing",BigDecimal.valueOf(freezing).setScale(2,BigDecimal.ROUND_HALF_DOWN));
			aj.put("integral",BigDecimal.valueOf(account.getIntegral()).setScale(2,BigDecimal.ROUND_HALF_DOWN));
		} else {
			aj.setSuccess(false);
			aj.setMsg("找不到用户");
		}
		return aj;
	}
	
	
	
	@ResponseBody
	@PostMapping("setTranspwd")
	@ApiOperation(notes = "设置/修改交易密码", value = "设置/修改交易密码")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "memberid", value = "用户id", dataType = "String", paramType = "query", required = true),
			@ApiImplicitParam(name = "transpwd", value = "交易密码", dataType = "String", paramType = "query", required = true), })
	public AjaxJson setTranspwd(HttpServletRequest request, HttpServletResponse response) {
		AjaxJson aj = new AjaxJson();
		String memberid = request.getParameter("memberid");
		String transpwd = request.getParameter("transpwd");
		Member member = memberService.get(memberid);
		if (member != null) {
			member.setTranspwd(SystemService.entryptPassword(transpwd));
			memberService.save(member);
			aj.setSuccess(true);
			aj.setMsg("交易密码设置成功");
		} else {
			aj.setSuccess(false);
			aj.setMsg("找不到用户");
		}
		return aj;
	}

	@ResponseBody
	@GetMapping("checkTranspwd")
	@ApiOperation(notes = "校验交易密码", value = "校验交易密码")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "memberid", value = "用户id", dataType = "String", paramType = "query", required = true),
			@ApiImplicitParam(name = "pwd", value = "交易密码", dataType = "String", paramType = "query", required = true) })
	public AjaxJson checkTranspwd(HttpServletRequest request, HttpServletResponse response) {
		AjaxJson aj = new AjaxJson();
		String memberid = request.getParameter("memberid");
		String pwd = request.getParameter("pwd");
		Member member = memberService.get(memberid);
		if (member != null) {
			boolean f = SystemService.validatePassword(pwd, member.getTranspwd());
			if (f) {
				aj.setSuccess(true);
				aj.setMsg("交易密码正确");
			} else {
				aj.setSuccess(false);
				aj.setMsg("交易密码错误");
			}
		} else {
			aj.setSuccess(false);
			aj.setMsg("找不到用户");
		}
		return aj;
	}
	
	
	
	
	@ResponseBody
	@PostMapping("saveIDInfo")
	@ApiOperation(notes = "保存实名信息", value = "保存实名信息")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "memberid", value = "用户id", dataType = "String", paramType = "query", required = true),
			@ApiImplicitParam(name = "name", value = "身份证姓名", dataType = "String", paramType = "query", required = true),
			@ApiImplicitParam(name = "IDcode", value = "身份证号", dataType = "String", paramType = "query", required = true)
	})
	public AjaxJson saveIDInfo(HttpServletRequest request, HttpServletResponse response) {
		AjaxJson aj = new AjaxJson();
		String memberid = request.getParameter("memberid");
		String name = request.getParameter("name");
		String IDcode = request.getParameter("IDcode");
//		String idcodeImgFront = request.getParameter("idcodeImgFront");
//		String idcodeImgBehind = request.getParameter("idcodeImgBehind");
//		if (StringUtils.isBlank(idcodeImgFront)){
//			aj.setSuccess(false);
//			aj.setMsg("请上传指定照片！");
//			return aj;
//		}

		Member member = memberService.get(memberid);

		//验证身份证号已认证
		Member mem = new Member();
//		mem.setName(name);
		mem.setIdcode(IDcode);
		List<Member> memberList = memberService.findList(mem);
		if (memberList.size()>0){
			if ("0".equals(memberList.get(0).getConfirmFlag()) || "1".equals(memberList.get(0).getConfirmFlag())){
				aj.setSuccess(false);
				aj.setMsg("该身份证号已认证！");
				return aj;
			}
		}

		if (member != null) {
			aj = memberService.checkID(member,name,IDcode);
		} else {
			aj.setSuccess(false);
			aj.setMsg("找不到用户");
		}
		return aj;
	}

	
	
	@ResponseBody
	@PostMapping("saveUserbank")
	@ApiOperation(notes = "保存用户银行卡", value = "保存用户银行卡")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "memberid", value = "用户id", dataType = "String", paramType = "query", required = true),
			@ApiImplicitParam(name = "name", value = "开户人姓名", dataType = "String", paramType = "query", required = true),
			@ApiImplicitParam(name = "bankname", value = "开户行", dataType = "String", paramType = "query", required = true),
			@ApiImplicitParam(name = "bankno", value = "卡号", dataType = "String", paramType = "query", required = true) })
	public AjaxJson saveUserbank(HttpServletRequest request, HttpServletResponse response) {
		AjaxJson aj = new AjaxJson();
		String memberid = request.getParameter("memberid");
		String name = request.getParameter("name");
		String bankname = request.getParameter("bankname");
		String bankno = request.getParameter("bankno");
//		if (!bankname.contains("支行")){
//			aj.setSuccess(false);
//			aj.setMsg("银行名称请精确到具体支行");
//			return aj;
//		}
		Member member = memberService.get(memberid);
		if (member != null) {
			Userbank userbank = userbankService.getByMember(memberid);
			if (userbank != null) {
				userbank.setName(name);
				userbank.setBankname(bankname);
				userbank.setBankno(bankno);
				userbankService.save(userbank);
			} else {
				userbank = new Userbank();
				userbank.setMember(member);
				userbank.setName(name);
				userbank.setBankname(bankname);
				userbank.setBankno(bankno);
				userbankService.save(userbank);
			}
			aj.setSuccess(true);
			aj.setMsg("收款银行卡设置成功");
		} else {
			aj.setSuccess(false);
			aj.setMsg("找不到用户");
		}
		return aj;
	}

	@ResponseBody
	@PostMapping("saveUserpay")
	@ApiOperation(notes = "保存用户支付宝", value = "保存用户支付宝")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "memberid", value = "用户id", dataType = "String", paramType = "query", required = true),
//			@ApiImplicitParam(name = "name", value = "姓名", dataType = "String", paramType = "query", required = true),
//			@ApiImplicitParam(name = "account", value = "支付宝账号", dataType = "String", paramType = "query", required = true),
			@ApiImplicitParam(name = "img", value = "收款码", dataType = "String", paramType = "query", required = false) })
	public AjaxJson saveUserpay(HttpServletRequest request, HttpServletResponse response) {
		AjaxJson aj = new AjaxJson();
		String memberid = request.getParameter("memberid");
//		String name = request.getParameter("name");
//		String account = request.getParameter("account");
		String img = request.getParameter("img");
		Member member = memberService.get(memberid);
		if (member != null) {
			Userpay userpay = userpayService.getByMember(memberid);
			if (userpay != null) {
//				userpay.setName(name);
//				userpay.setAccount(account);
				if (StringUtils.isNotEmpty(img)) {
					userpay.setImg(img);
				}
				userpayService.save(userpay);
			} else {
				userpay = new Userpay();
				userpay.setMember(member);
//				userpay.setName(name);
//				userpay.setAccount(account);
				if (StringUtils.isNotEmpty(img)) {
					userpay.setImg(img);
				}
				userpayService.save(userpay);
			}
			aj.setSuccess(true);
			aj.setMsg("收款支付宝设置成功");
		} else {
			aj.setSuccess(false);
			aj.setMsg("找不到用户");
		}
		return aj;
	}

	@ResponseBody
	@PostMapping("saveUserwx")
	@ApiOperation(notes = "保存用户微信", value = "保存用户微信")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "memberid", value = "用户id", dataType = "String", paramType = "query", required = true),
//			@ApiImplicitParam(name = "name", value = "姓名", dataType = "String", paramType = "query", required = true),
//			@ApiImplicitParam(name = "wxno", value = "微信号", dataType = "String", paramType = "query", required = true),
			@ApiImplicitParam(name = "img", value = "收款码", dataType = "String", paramType = "query", required = false) })
	public AjaxJson saveUserwx(HttpServletRequest request, HttpServletResponse response) {
		AjaxJson aj = new AjaxJson();
		String memberid = request.getParameter("memberid");
//		String name = request.getParameter("name");
//		String wxno = request.getParameter("wxno");
		String img = request.getParameter("img");
		Member member = memberService.get(memberid);
		if (member != null) {
			Userwx userwx = userwxService.getByMember(memberid);
			if (userwx != null) {
//				userwx.setName(name);
//				userwx.setWxno(wxno);
				if (StringUtils.isNotEmpty(img)) {
					userwx.setImg(img);
				}
				userwxService.save(userwx);
			} else {
				userwx = new Userwx();
				userwx.setMember(member);
//				userwx.setName(name);
//				userwx.setWxno(wxno);
				if (StringUtils.isNotEmpty(img)) {
					userwx.setImg(img);
				}
				userwxService.save(userwx);
			}
			aj.setSuccess(true);
			aj.setMsg("收款微信设置成功");
		} else {
			aj.setSuccess(false);
			aj.setMsg("找不到用户");
		}
		return aj;
	}

	
	
	@ResponseBody
	@PostMapping("setMemberImg")
	@ApiOperation(notes = "设置用户头像", value = "设置用户头像")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "memberid", value = "用户id", dataType = "String", paramType = "query", required = true),
			@ApiImplicitParam(name = "img", value = "图片地址", dataType = "String", paramType = "query", required = true) })
	public AjaxJson setMemberImg(HttpServletRequest request, HttpServletResponse response) {
		AjaxJson aj = new AjaxJson();
		String memberid = request.getParameter("memberid");
		String img = request.getParameter("img");
		Member member = memberService.get(memberid);
		if (member != null) {
			member.setImg(img);
			memberService.save(member);
			aj.setSuccess(true);
			aj.setMsg("头像设置成功");
		} else {
			aj.setSuccess(false);
			aj.setMsg("找不到用户");
		}
		return aj;
	}
	
	
	@ResponseBody
	@GetMapping("getMemberCollection")
	@ApiOperation(notes = "获取用户收款信息",value = "获取用户收款信息")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "memberid",value = "用户id",dataType = "String",paramType = "query",required = true)
	})
	public AjaxJson getMemberCollection(HttpServletRequest request,HttpServletResponse response) {
		AjaxJson aj = new AjaxJson();
		String memberid = request.getParameter("memberid");
		Member member = memberService.get(memberid);
		if(member != null) {
			Userbank userbank = new Userbank();
			userbank.setMember(member);
			List<Userbank> listUserbanks = userbankService.findList(userbank);
			if(listUserbanks.size()>0) {
				aj.put("userbank", listUserbanks.get(0));
			}else {
				aj.put("userbank", new Userbank());
			}
			Userpay userpay = new Userpay();
			userpay.setMember(member);
			List<Userpay> listUserpays = userpayService.findList(userpay);
			if(listUserpays.size()>0) {
				aj.put("userpay", listUserpays.get(0));
			}else {
				aj.put("userpay", new Userpay());
			}
			Userwx userwx = new Userwx();
			userwx.setMember(member);
			List<Userwx> listUserwxs = userwxService.findList(userwx);
			if(listUserwxs.size()>0) {
				aj.put("userwx", listUserwxs.get(0));
			}else {
				aj.put("userwx", new Userwx());
			}
			aj.setSuccess(true);
		}else {
			aj.setSuccess(false);
			aj.setMsg("找不到用户");
		}
		return aj;
	}


	@ResponseBody
	@PostMapping("saveRegion")
	@ApiOperation(notes = "保存地区", value = "保存地区")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "memberid", value = "用户id", dataType = "String", paramType = "query", required = true),
			@ApiImplicitParam(name = "regionPlace", value = "所属地区", dataType = "String", paramType = "query", required = true), })
	public AjaxJson saveRegion(HttpServletRequest request, HttpServletResponse response) {
		AjaxJson aj = new AjaxJson();
		String memberid = request.getParameter("memberid");
		String regionPlace = request.getParameter("regionPlace");
		Member member = memberService.get(memberid);
		if (member != null) {
			member.setRegionPlace(regionPlace);
			memberService.save(member);
		} else {
			aj.setSuccess(false);
			aj.setMsg("找不到用户");
		}
		return aj;
	}


	@ResponseBody
	@GetMapping("getAccountNumber")
	@ApiOperation(notes = "获取分红数字", value = "获取分红数字")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "memberid", value = "用户id", dataType = "String", paramType = "query", required = true) })
	public AjaxJson getAccountNumber(HttpServletRequest request, HttpServletResponse response) {
		AjaxJson aj = new AjaxJson();
		String memberid = request.getParameter("memberid");
		Member member = memberService.get(memberid);
		//总资产
		Double totalAssets = 0.0;
		//持仓
		Double position = 0.0;
		//锁仓
		Double freezing = 0.0;
		//分红数字
		double star = 0.0;
		if (member != null) {
			Member member1 = new Member();
			member1.setP(member);
			List<Member> memberList = memberService.findList(member1);
			//查询团队下级人员
			List<Member>  queryList = new ArrayList<>();
			//最终集合
			List<Member> list = new ArrayList<>();
			queryList.addAll(memberList);
			list.addAll(memberList);
			while (list.size()>0){
				list.clear();
				List<Member> list1 = new ArrayList<>();
				for (Member member2 : queryList) {
					Member entity = new Member();
					entity.setP(member2);
					List<Member> memberList1 = memberService.findList(entity);
					memberList.addAll(memberList1);
					list1.addAll(memberList1);
				}
				list.addAll(list1);
				queryList.clear();
				queryList.addAll(list1);
			}
			for (Member member2 : memberList) {
				if ("2".equals(member2.getUsertype())){
					star += 0.5;
				}else if ("3".equals(member2.getUsertype())){
					star += 1;
				}
			}
			//钱包信息
			Account account = accountService.get(member.getAccount().getId());
			if (account == null){
				aj.setSuccess(false);
				aj.setMsg("钱包信息有误");
				return aj;
			}
			//持仓资产
			PositionAssets positionAssets = new PositionAssets();
			positionAssets.setMember(member);
			positionAssets.setIsApply("0");
			List<PositionAssets> positionAssetsList = positionAssetsService.findList(positionAssets);
			if (positionAssetsList.size()>0){
				position = positionAssetsList.stream().mapToDouble(PositionAssets::getNowTotal).sum();
			}
			//锁仓
			FreezingAssets freezingAssets = new FreezingAssets();
			freezingAssets.setMember(member);
			freezingAssets.setIsApply("0");
			List<FreezingAssets> freezingAssetsList = freezingAssetsService.findList(freezingAssets);
			if (freezingAssetsList.size()>0){
				freezing = freezingAssetsList.stream().mapToDouble(FreezingAssets::getNowTotal).sum();
			}
			totalAssets = account.getYue() + position + freezing;
			star = BigDecimal.valueOf(totalAssets).divide(BigDecimal.valueOf(2500),1,BigDecimal.ROUND_HALF_DOWN).add(BigDecimal.valueOf(star)).doubleValue();
			aj.setSuccess(true);
			aj.put("star",star);
		} else {
			aj.setSuccess(false);
			aj.setMsg("找不到用户");
		}
		return aj;
	}


	@ResponseBody
	@GetMapping("isHaveTradePassword")
	@ApiOperation(notes = "判断是否有交易密码", value = "判断是否有交易密码")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "memberid", value = "用户id", dataType = "String", paramType = "query", required = true) })
	public AjaxJson isHaveTradePassword(HttpServletRequest request, HttpServletResponse response) {
		AjaxJson aj = new AjaxJson();
		String memberid = request.getParameter("memberid");
		Member member = memberService.get(memberid);
		if (member != null) {
			if (StringUtils.isNotBlank(member.getTranspwd())){
				aj.put("flag","1");
			}else {
				aj.put("flag","0");
			}
			aj.put("phone",member.getMobile());
			aj.setSuccess(true);
		} else {
			aj.setSuccess(false);
			aj.setMsg("找不到用户");
		}
		return aj;
	}


	@ResponseBody
	@GetMapping("isHaveIgnore")
	@ApiOperation(notes = "判断是否忽略去完善银行卡", value = "判断是否忽略去完善银行卡")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "memberid", value = "用户id", dataType = "String", paramType = "query", required = true) })
	public AjaxJson isHaveIgnore(HttpServletRequest request, HttpServletResponse response) {
		AjaxJson aj = new AjaxJson();
		String memberid = request.getParameter("memberid");
		Member member = memberService.get(memberid);
		if (member != null) {
			Userbank userbank = userbankService.getByMember(memberid);
			if (userbank != null) {
				member.setIsIgnore("1");
			}
			aj.put("isIgnore",member.getIsIgnore());
			aj.setSuccess(true);
		} else {
			aj.setSuccess(false);
			aj.setMsg("找不到用户");
		}
		return aj;
	}



	@ResponseBody
	@PostMapping("ignore")
	@ApiOperation(notes = "忽略完善银行卡", value = "忽略完善银行卡")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "memberid", value = "用户id", dataType = "String", paramType = "query", required = true),
	})
	public AjaxJson ignore(HttpServletRequest request, HttpServletResponse response) {
		AjaxJson aj = new AjaxJson();
		String memberid = request.getParameter("memberid");
		Member member = memberService.get(memberid);
		if (member != null) {
			member.setIsIgnore("1");
			memberService.save(member);
			aj.setSuccess(true);
		} else {
			aj.setSuccess(false);
			aj.setMsg("找不到用户");
		}
		return aj;
	}
	
}
